<?php

use yii\grid\ActionColumn;
use yii\grid\CheckboxColumn;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Backend Users';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="backend-user-index">

<!--    <h1>--><?//= Html::encode($this->title) ?><!--</h1>-->

    <p>
        <?= Html::a('添加管理员', ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a('批量删除', "javascript:void(0);", ['class' => 'btn btn-success gridview']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'id' => 'grid',

        'columns' => [
            [
                'class'=>CheckboxColumn::className(),
                'name'=>'username',  //设置每行数据的复选框属性
                'headerOptions' => ['width'=>'30'],
            ],
            ['class' => 'yii\grid\SerialColumn'],
//            'id',
            'username',
//            'auth_key',
            'password_hash',
//            'password_reset_token',
            // 'email:email',
            // 'role',
            // 'status',
//             'created_at',
            ['attribute'=>'created_at',
                'format'=>['date','php:Y-m-d H:i:s'],
            ],
            // 'updated_at',
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{update} {delete} {fenpei}',
                'buttons'=>
                    [
                        'fenpei'=>function($url,$model,$key)
                        {
                            $options=[
                                'title'=>Yii::t('yii', '分配权限'),
                                'aria-label'=>Yii::t('yii','分配权限'),
//                                'data-confirm'=>Yii::t('yii','你确定通过这条评论吗？'),
                                'data-method'=>'post',
                                'data-pjax'=>'0',
                            ];
                            return Html::a('<button class="glyphicon glyphicon-user  btn btn-white btn-sm">权限</button>',$url,$options);

                        },
                    ],


            ],
        ],
    ]); ?>

</div>


<?php
$this->registerJs('
$(".gridview").on("click", function () {
//注意这里的$("#grid")，要跟我们第一步设定的options id一致
var keys = $("#grid").yiiGridView("getSelectedRows");
alert("待开发");
});
');
?>